home *** CD-ROM | disk | FTP | other *** search
/ PC World 2008 March / PCWorld_2008-03_cd.bin / v cisle / mobiDVD / MobiDVD-1.0.0.6.exe / xulrunner / components / jsconsole-clhandler.js < prev    next >
Text File  |  2007-07-27  |  5KB  |  132 lines

  1. //@line 41 "/cygdrive/d/builds/tinderbox/XR-Trunk/WINNT_5.2_Depend/mozilla/toolkit/components/console/jsconsole-clhandler.js"
  2.  
  3. /*
  4.  * -jsconsole commandline handler; starts up the Error console.
  5.  */
  6.  
  7. const nsISupports           = Components.interfaces.nsISupports;
  8. const nsICategoryManager    = Components.interfaces.nsICategoryManager;
  9. const nsIComponentRegistrar = Components.interfaces.nsIComponentRegistrar;
  10. const nsICommandLine        = Components.interfaces.nsICommandLine;
  11. const nsICommandLineHandler = Components.interfaces.nsICommandLineHandler;
  12. const nsIFactory            = Components.interfaces.nsIFactory;
  13. const nsIModule             = Components.interfaces.nsIModule;
  14. const nsIWindowWatcher      = Components.interfaces.nsIWindowWatcher;
  15. const nsIWindowMediator     = Components.interfaces.nsIWindowMediator;
  16.  
  17. /*
  18.  * Classes
  19.  */
  20.  
  21. const jsConsoleHandler = {
  22.     /* nsISupports */
  23.     QueryInterface : function clh_QI(iid) {
  24.         if (iid.equals(nsICommandLineHandler) ||
  25.             iid.equals(nsIFactory) ||
  26.             iid.equals(nsISupports))
  27.             return this;
  28.  
  29.         throw Components.results.NS_ERROR_NO_INTERFACE;
  30.     },
  31.  
  32.     /* nsICommandLineHandler */
  33.  
  34.     handle : function clh_handle(cmdLine) {
  35.         if (!cmdLine.handleFlag("jsconsole", false))
  36.             return;
  37.  
  38.         var windowMediator = Components.classes["@mozilla.org/appshell/window-mediator;1"]
  39.                                        .getService(nsIWindowMediator);
  40.         var console = windowMediator.getMostRecentWindow("global:console");
  41.         if (!console) {
  42.           var wwatch = Components.classes["@mozilla.org/embedcomp/window-watcher;1"]
  43.                                  .getService(nsIWindowWatcher);
  44.           wwatch.openWindow(null, "chrome://global/content/console.xul", "_blank",
  45.                             "chrome,dialog=no,all", cmdLine);
  46.         } else {
  47.           // the Error console was already open
  48.           console.focus();
  49.         }
  50.  
  51.         // note that since we don't prevent the default action, you'll get
  52.         // an additional application window, unless you specified another
  53.         // command line flag
  54.     },
  55.  
  56.     helpInfo : "  -jsconsole           Open the Error console.\n",
  57.  
  58.     /* nsIFactory */
  59.  
  60.     createInstance : function clh_CI(outer, iid) {
  61.         if (outer != null)
  62.             throw Components.results.NS_ERROR_NO_AGGREGATION;
  63.  
  64.         return this.QueryInterface(iid);
  65.     },
  66.  
  67.     lockFactory : function clh_lock(lock) {
  68.         /* no-op */
  69.     }
  70. };
  71.  
  72. const clh_contractID = "@mozilla.org/toolkit/console-clh;1";
  73. const clh_CID = Components.ID("{2cd0c310-e127-44d0-88fc-4435c9ab4d4b}");
  74. const clh_category = "c-jsconsole";
  75.  
  76. const jsConsoleHandlerModule = {
  77.     /* nsISupports */
  78.  
  79.     QueryInterface : function mod_QI(iid) {
  80.         if (iid.equals(nsIModule) ||
  81.             iid.equals(nsISupports))
  82.             return this;
  83.  
  84.         throw Components.results.NS_ERROR_NO_INTERFACE;
  85.     },
  86.  
  87.     /* nsIModule */
  88.  
  89.     getClassObject : function mod_gch(compMgr, cid, iid) {
  90.         if (cid.equals(clh_CID))
  91.             return jsConsoleHandler.QueryInterface(iid);
  92.  
  93.         throw Components.results.NS_ERROR_NOT_REGISTERED;
  94.     },
  95.  
  96.     registerSelf : function mod_regself(compMgr, fileSpec, location, type) {
  97.         compMgr.QueryInterface(nsIComponentRegistrar);
  98.  
  99.         compMgr.registerFactoryLocation(clh_CID,
  100.                                         "jsConsoleHandler",
  101.                                         clh_contractID,
  102.                                         fileSpec,
  103.                                         location,
  104.                                         type);
  105.  
  106.         var catMan = Components.classes["@mozilla.org/categorymanager;1"]
  107.                                .getService(nsICategoryManager);
  108.         catMan.addCategoryEntry("command-line-handler",
  109.                                 clh_category,
  110.                                 clh_contractID, true, true);
  111.     },
  112.  
  113.     unregisterSelf : function mod_unreg(compMgr, location, type) {
  114.         compMgr.QueryInterface(nsIComponentRegistrar);
  115.  
  116.         compMgr.unregisterFactoryLocation(clh_CID, location);
  117.  
  118.         var catMan = Components.classes["@mozilla.org/categorymanager;1"]
  119.                                .getService(nsICategoryManager);
  120.         catMan.deleteCategoryEntry("command-line-handler", clh_category);
  121.     },
  122.  
  123.     canUnload : function (compMgr) {
  124.         return true;
  125.     }
  126. };
  127.  
  128. /* module initialisation */
  129. function NSGetModule(comMgr, fileSpec) {
  130.     return jsConsoleHandlerModule;
  131. }
  132.